#!/bin/sh

##########################
HOME_NAME=huangjunjia
STORAGE_LOCATION=/home/$HOME_NAME/code/anythingllm-docker
DOCKER_NAME=anythingllm
##########################
# 这里加777权限是必要的
echo "本地路径 $STORAGE_LOCATION"
mkdir -p $STORAGE_LOCATION
chmod 777 $STORAGE_LOCATION

touch "$STORAGE_LOCATION/.env"
chmod 777 "$STORAGE_LOCATION/.env"

# check
if [[ -n $(docker ps -q -f "name=${DOCKER_NAME}") ]];then
        echo "not exist docker name=${DOCKER_NAME}"
else
    echo "exist docker name=${DOCKER_NAME}. neet exit, then rm docker."
    docker rm ${DOCKER_NAME}
fi

# 构建容器实例
docker run -d \
-p 29543:3001 \
--cap-add SYS_ADMIN \
-v ${STORAGE_LOCATION}:/app/server/storage \
-v ${STORAGE_LOCATION}/.env:/app/server/.env \
-e STORAGE_DIR="/app/server/storage" \
--name ${DOCKER_NAME} \
mintplexlabs/anythingllm

